package com.xxh.market.dao.impl;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import com.xxh.market.dao.ShopCarDao;
import com.xxh.market.entity.vo.ShopCarVo;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ShopCarDaoImpl implements ShopCarDao {
    @Override
    public List<ShopCarVo> getShopListByUid(Integer uid) {
        try {
            List<ShopCarVo> shopCarVos = new ArrayList<>();
            List<Entity> entityList = Db.use().query("select * from books ,user ,shopcar  where  books.bid=shopcar.bid and shopcar.uid=user.uid =?", uid);
            entityList.stream().forEach(entity -> {
                ShopCarVo shopCarVo = new ShopCarVo();
                shopCarVo.setBname(entity.getStr("bname"));
                shopCarVo.setBookprice(entity.getDouble("price"));
                shopCarVo.setUname(entity.getStr("username"));
                shopCarVo.setUid(uid);
                shopCarVo.setBid(entity.getInt("bid"));
                shopCarVos.add(shopCarVo);
            });
            return shopCarVos;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
